package com.hxwm.entity;

import java.sql.Connection;
import java.sql.DriverManager;

public class DateSource{
    private String url;
    private String user;
    private String password;
    public DateSource(String url, String user, String password) {
        this.url = url;
        this.user = user;
        this.password = password;
    }
    public Connection getConnection() throws Exception {
        String driverType = this.url.split(":")[1];
        if("db2".equals(driverType)) {
            Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
        }else if("mysql".equals(driverType)){
            Class.forName("com.mysql.cj.jdbc.Driver").newInstance();
        }else if("oracle".equals(driverType)){
            Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
        }
        return DriverManager.getConnection(url,user,password);
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getUser() {
        return user;
    }
    public void setUser(String user) {
        this.user = user;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
}